package com.lg.baselibrary.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.AttributeSet;

/**
 * Created by LiGang on 2017/5/27.
 */

public class BaseRecyclerView extends RecyclerView{

    public BaseRecyclerView(Context context) {
        super(context);
    }

    public BaseRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setLinearLayoutManager(int orientation){
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        layoutManager.setOrientation(orientation);
        setLayoutManager(layoutManager);
    }
    public void setGridLayoutManager(int spanCount){
        GridLayoutManager layoutManager = new GridLayoutManager(getContext(),spanCount);
        setLayoutManager(layoutManager);
    }
    public void setStaggeredGridLayoutManager(int spanCount, int orientation){
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(spanCount,orientation);
        setLayoutManager(layoutManager);
    }
    @Override
    public void setAdapter(Adapter adapter) {
        if(getLayoutManager() == null){
            setLinearLayoutManager(LinearLayoutManager.VERTICAL);
        }
        super.setAdapter(adapter);
    }
}
